package com.kefan.reptilemanagement.controller;


import com.kefan.reptilemanagement.common.entities.ResultBody;
import com.kefan.reptilemanagement.common.entities.Task;
import com.kefan.reptilemanagement.utils.RabbitUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sjj
 * @since 2024-05-03
 */
@RestController
@RequestMapping("/task")
public class TaskController extends BaseController {
    @Autowired
    RabbitUtils rabbitUtils;
    @PostMapping("/send")
    public ResultBody sendMessage(String message,String rk)
    {
        rabbitUtils.createOrBindQueue(rk,rk);
        queueServer.sendMessage(message, rk);
        return ResultBody.success();
    }
    @PostMapping("/add")
    public ResultBody add(@RequestBody Task task)
    {
        return ResultBody.success(taskService.add(task));
    }
    @GetMapping("/list")
    public ResultBody getList(@RequestParam(value = "userId",required = false) Long userId,@RequestParam(value = "status",required = false) Integer status,@RequestParam(value = "name",required = false) String name)
    {
        return ResultBody.success(taskService.getList(userId, status, name));
    }
    @DeleteMapping("/delete")
    public ResultBody delete(@RequestParam("id") Long id)
    {
        return ResultBody.success(taskService.delete(id));
    }
    @GetMapping("/current")
    public ResultBody getCurrent()
    {
        return ResultBody.success(taskService.getCurrent());
    }
    @GetMapping("/download")
    public ResultBody getResFile(@RequestParam("id") Long id)
    {
        return ResultBody.success(taskService.getResFile(id));
    }
}
